package org.kfive.nova.hadoop.mapper;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;
import java.util.StringTokenizer;

/*
* MultiTableJoinMapper.java
* Created  by  lizhanwu
* Created on 2016/4/20 19:36
*/
public class MultiTableJoinMapper extends Mapper<LongWritable,Text,Text,Text> {

    public void map(LongWritable key,Text value,Context context) throws IOException,InterruptedException{

        String line = value.toString();

        StringTokenizer tokenizer = new StringTokenizer(line,"\t");

        int i = 0;

        Text mapKey = null;
        Text mapValue = null;
        while (tokenizer.hasMoreTokens()){
            String col1 = tokenizer.nextToken();
            if(col1.charAt(0)>='0' && col1.charAt(0)<='9'){
                mapKey = new Text(col1);
            }else {
                if(i<=0){
                    mapValue = new Text("1"+col1);
                }else {
                    mapValue = new Text("2"+col1);
                }
            }
            i++;
        }
        context.write(mapKey,mapValue);
    }

}
